﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Meqs.Entity;
using System.Collections.Generic;
using System.Web.Services;
using Meqs.Utilities;
using Meqs.Logic.Interface;

public partial class TeacherEval_School_Reprots_TeacherMonthEval : System.Web.UI.Page
{
    protected string KeyWord
    {
        get
        {
            return TeacherEvalHistory.Teacher_Month_Eval;
        }
    }
    protected IList<UserProjectScore> ups = null;
    protected IList<Meqs.Entity.YearAndMonth> yearandmonth = null;
    protected int index = 0;
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnBind_Click(object sender, EventArgs e)
    {
        int id = Convert.ToInt32(Request.Form[schoolCause.UniqueID].ToString());
        Hashtable ht = new Hashtable();
        ht.Add("SchoolMark", Common.GetConstSchoolMark());
        ht.Add("KeyWord", KeyWord);
        ht.Add("SchoolYear", Convert.ToInt32(Request.Form[schoolYear.UniqueID].ToString()));
        ht.Add("Term", Convert.ToInt32(Request.Form[schoolTerm.UniqueID].ToString()));
        ups = Container<ITeacherEvalCatchLogic>.Instance.FindKeyWordMonthInfo(ht);
        yearandmonth = Container<ITeacherEvalCatchLogic>.Instance.FindKeyWordYearMonth(ht);

        ht = new Hashtable();
        ht.Add("CauseID", id);
        Repeater1.DataSource = Container<ITeacherEvalDesLogic>.Instance.FindCauseTeacher(ht);
        Repeater1.DataBind();

    }

    protected string GetHeader()
    {
        string str = "<tr>";
        str += "<th>姓名（工号）<span  id='img0'></span></th>";
        index = 1;
        foreach (Meqs.Entity.YearAndMonth type in yearandmonth)
        {
            str += "<th onclick='sort(" + index + ")'>" + type.Year + "年" + type .Month + "月(均分)<span  id='img" + index + "'></span></th>";
            index++;
        }
        str += "<th onclick='sort(" + index + ")'>总评分<span id='img" + index + "'><img src='../../Common/images/1.gif' /></span></th></tr>";
        
        return str;
    }
    protected string GetTeacher(int id, string name, string coder)
    {
        string str = "<tr onclick='SetHightLight(this);'>";
        str += "<td>" + name + "（" + coder + "）</td>";
        float totle = 0;

        foreach (Meqs.Entity.YearAndMonth type in yearandmonth)
        {
            object s = GetTypeScore(id, type.Year,type.Month);
            totle += (s == null) ? (float)0 : (float)(Math.Round(Convert.ToSingle(s), 1));
            string scorestr = (s == null) ? "" : Math.Round(Convert.ToSingle(s), 1).ToString();
            str += "<td >" + scorestr + "</td>";
        }
        str += "<td >" + totle + "</td></tr>";
        return str;
    }
    protected object GetTypeScore(int id, int year,int month)
    {
        foreach (UserProjectScore u in ups)
        {
            if (u.UserID == id && u.Year == year && u.Month == month)
            {
                return u.Score;
            }
        }
        return null;
    }
    [WebMethod]
    public static string GetExcel(ExcelTableCell[][] cells)
    {
        string temp_path = HttpContext.Current.Server.MapPath("../../../");
        string save_path = temp_path + "\\download\\" + "任课教师日常评价.xls";
        HttpContext.Current.Session["filepath"] = save_path;
        Meqs.Utilities.ExcelUtil.ExcelExport(save_path, "任课教师日常评价", 1, 0, cells);
        return "";
    }
}
